{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Count Vowel Strings in Ranges"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #string #prefix-sum"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #字符串 #前缀和"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: vowelStrings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #统计范围内的元音字符串数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个下标从 <strong>0</strong> 开始的字符串数组 <code>words</code> 以及一个二维整数数组 <code>queries</code> 。</p>\n",
    "\n",
    "<p>每个查询 <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> 会要求我们统计在 <code>words</code> 中下标在 <code>l<sub>i</sub></code> 到 <code>r<sub>i</sub></code> 范围内（<strong>包含</strong> 这两个值）并且以元音开头和结尾的字符串的数目。</p>\n",
    "\n",
    "<p>返回一个整数数组，其中数组的第 <code>i</code> 个元素对应第 <code>i</code> 个查询的答案。</p>\n",
    "\n",
    "<p><strong>注意：</strong>元音字母是 <code>'a'</code>、<code>'e'</code>、<code>'i'</code>、<code>'o'</code> 和 <code>'u'</code> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>words = [\"aba\",\"bcb\",\"ece\",\"aa\",\"e\"], queries = [[0,2],[1,4],[1,1]]\n",
    "<strong>输出：</strong>[2,3,0]\n",
    "<strong>解释：</strong>以元音开头和结尾的字符串是 \"aba\"、\"ece\"、\"aa\" 和 \"e\" 。\n",
    "查询 [0,2] 结果为 2（字符串 \"aba\" 和 \"ece\"）。\n",
    "查询 [1,4] 结果为 3（字符串 \"ece\"、\"aa\"、\"e\"）。\n",
    "查询 [1,1] 结果为 0 。\n",
    "返回结果 [2,3,0] 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>words = [\"a\",\"e\",\"i\"], queries = [[0,2],[0,1],[2,2]]\n",
    "<strong>输出：</strong>[3,2,1]\n",
    "<strong>解释：</strong>每个字符串都满足这一条件，所以返回 [3,2,1] 。</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= words.length &lt;= 10<sup>5</sup></code></li>\n",
    "\t<li><code>1 &lt;= words[i].length &lt;= 40</code></li>\n",
    "\t<li><code>words[i]</code> 仅由小写英文字母组成</li>\n",
    "\t<li><code>sum(words[i].length) &lt;= 3 * 10<sup>5</sup></code></li>\n",
    "\t<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>\n",
    "\t<li><code>0 &lt;= queries[j][0] &lt;= queries[j][1] &lt;&nbsp;words.length</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [count-vowel-strings-in-ranges](https://leetcode.cn/problems/count-vowel-strings-in-ranges/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [count-vowel-strings-in-ranges](https://leetcode.cn/problems/count-vowel-strings-in-ranges/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[\"aba\",\"bcb\",\"ece\",\"aa\",\"e\"]\\n[[0,2],[1,4],[1,1]]', '[\"a\",\"e\",\"i\"]\\n[[0,2],[0,1],[2,2]]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(left,right+1):\n",
    "            if words[i][0] in 'aeiou' and words[i][-1] in 'aeiou':\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        count = 0\n",
    "        for i in range(left,right+1):\n",
    "            if words[i][0] in \"aeiou\" and words [i][-1] in \"aeiou\":\n",
    "                count = count+1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        ret = 0\n",
    "        a = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "\n",
    "        for i in range(left,right+1):\n",
    "            if words[i][0] in a and words[i][-1] in a:\n",
    "                ret = ret+1\n",
    "        \n",
    "        return ret\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return len([x for x in words[left:right + 1] if x[0] in {'a','e','i','o','u'} and x[-1] in {'a','e','i','o','u'}])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        ans=0\n",
    "        dic={'a','e','i','o','u'}\n",
    "        for i in range(left,right+1):\n",
    "            # n=len(words[i])\n",
    "            if words[i][0] in dic and words[i][-1] in dic:\n",
    "                    ans+=1\n",
    "            # continue\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowels = set(\"aeiou\")\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            word = words[i]\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        # vowels = {'a', 'e', 'i', 'o', 'u'}\n",
    "        vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "        # return sum(words[i][0] in vowels and words[i][- 1] in vowels for i in range(left, right + 1))\n",
    "        return sum(word[0] in vowels and word[-1] in vowels for word in words[left: right + 1])\n",
    "        # result = 0\n",
    "        # for i in range(left,right+1):\n",
    "        #     if words[i][0] in vowels and words[i][-1] in vowels:\n",
    "        #         result += 1\n",
    "        # return result\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        res = 0\n",
    "        yuanyin = set('aeiou')\n",
    "        for word in words[left:right+1]:\n",
    "            if word[0] in yuanyin and word[-1] in yuanyin:\n",
    "                res += 1\n",
    "\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        ret=0\n",
    "        for i in range(left,right+1):\n",
    "            w=words[i]\n",
    "            if w[0] in [\"a\",\"e\",\"i\",\"o\",\"u\"] and w[-1] in [\"a\",\"e\",\"i\",\"o\",\"u\"]:\n",
    "                ret+=1\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowels = set(\"aeiou\")\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            word = words[i]\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        count=0\n",
    "        lst=['a','e','i','o','u']\n",
    "        for i in words[left:right+1]:\n",
    "            if i[0] in lst and i[len(i)-1] in lst:\n",
    "                count+=1\n",
    "        return count\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "vowels = {'a', 'e', 'i', 'o', 'u'}\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return sum(1 for word in words[left: right + 1] if len(word) > 0 and word[0] in vowels and word[-1] in vowels)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        yuanyin = ['a', 'e', 'i', 'o', 'u']\n",
    "        i = left\n",
    "        res = 0\n",
    "        while i <= right:\n",
    "            word = words[i]\n",
    "            if word[0] in yuanyin and word[-1] in yuanyin:\n",
    "                res += 1\n",
    "            i += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        count = 0\n",
    "        vowel_list = set('aeiou')\n",
    "        for i in range(left, right+1):\n",
    "            if words[i][0] in vowel_list and words[i][-1] in vowel_list:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        count = 0\n",
    "        aeiou = ['a','e','i','o','u']\n",
    "        for i in range(left,right+1):\n",
    "            if words[i][0] in aeiou and words[i][-1] in aeiou:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return sum(word[0] in 'aeiou' and word[-1] in 'aeiou' for word in words[left:right + 1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        group = ['a', 'e', 'i', 'o', 'u']\n",
    "        res = 0\n",
    "        for i in range(left, right+1):\n",
    "            if words[i][0] in group and words[i][-1] in group:\n",
    "                res += 1\n",
    "        return res\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        alpha = set('aeiou')\n",
    "\n",
    "        ans = 0\n",
    "        for i in range(left, right+1):\n",
    "            if words[i][-1] in alpha and words[i][0] in alpha:\n",
    "                ans += 1\n",
    "        \n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    vowel_letters = {\"a\", \"e\", \"i\", \"o\", \"u\"}\n",
    "\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(left, right + 1):\n",
    "            word = words[i]\n",
    "            if self.vowelString(word):\n",
    "                res += 1\n",
    "        return res\n",
    "\n",
    "    def vowelString(self, word: str) -> bool: \n",
    "        return word[0] in self.vowel_letters and word[len(word) - 1] in self.vowel_letters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "vowels = {'a', 'e', 'i', 'o', 'u'}\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return sum(1 for word in words[left: right + 1] if len(word) > 0 and word[0] in vowels and word[-1] in vowels)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowels = set(\"aeiou\")\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            word = words[i]\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "  def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "    ans = 0\n",
    "    words = words[left: right+1]\n",
    "    for w in words:\n",
    "      if w[0] in 'aieou' and w[-1] in 'aieou':\n",
    "        ans+=1\n",
    "    return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        s1 = 'aeiou'\n",
    "        ans = 0\n",
    "        for i in range(left,right+1):\n",
    "            if words[i][0] in s1 and words[i][-1] in s1:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            word = words[i]\n",
    "            if word[0] in \"aeiou\" and word[-1] in \"aeiou\":\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        ans = 0\n",
    "        s = 'aeiou'\n",
    "        for i in range(left, right + 1):\n",
    "            x = words[i]\n",
    "            if x[0] in s and x[-1] in s:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowels = set(\"aeiou\")\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            word = words[i]\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        words = words[left:right+1]\n",
    "        ans = 0\n",
    "        origin = ['a','e','i','o','u']\n",
    "        for word in words:\n",
    "            if word[0] in origin and word[-1] in origin:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        res=0\n",
    "        d=[\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "        for i in range(left,right+1):\n",
    "            if words[i][0] in d and words[i][-1] in d:\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        aeiou = 'aeiou'\n",
    "        result = 0\n",
    "        for word in words[left:right+1]:\n",
    "            if word[0] in aeiou and word[-1] in aeiou:\n",
    "                result += 1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        d = defaultdict(int)\n",
    "        d['a'] = 1\n",
    "        d['e'] = 1\n",
    "        d['i'] = 1\n",
    "        d['o'] = 1\n",
    "        d['u'] = 1\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            ans += d[words[i][0]] & d[words[i][-1]]\n",
    "        return ans\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        s1 = set('aeiou')\n",
    "        ans = 0\n",
    "        for i in range(left,right+1):\n",
    "            if words[i][0] in s1 and words[i][-1] in s1:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        nums = 0\n",
    "        for i in range(max(0,left),min(len(words),right+1)):\n",
    "            j = len(words[i])\n",
    "            if str(words[i][0]) in 'aeiou' and str(words[i][j-1]) in 'aeiou' :\n",
    "                nums+=1\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        check = ['a', 'e', 'i', 'o', 'u']\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            if words[i][0] in check and words[i][-1] in check:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        List=['a','e','i','o','u']\n",
    "        an=0\n",
    "        for i in words[left:right+1]:\n",
    "            if(i[0] in List and i[-1] in List):\n",
    "                an+=1\n",
    "        return an"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        yy = [\"a\", \"e\", \"i\", \"o\", \"u\"]\n",
    "        out = 0\n",
    "        for i in words[left:right+1]:\n",
    "            if i[0] in yy and i[-1] in yy:\n",
    "                out += 1\n",
    "        return out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            if words[i][0] in \"aeiou\" and words[i][-1] in \"aeiou\":\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        s = 'aeiou'\n",
    "        count = 0 \n",
    "\n",
    "        for index in range(left, right+1):\n",
    "            word  = words[index]\n",
    "\n",
    "            left,right = word[0],word[-1]\n",
    "\n",
    "            if left in s and right in s:\n",
    "                count+=1\n",
    "\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return sum(s[0] in \"aeiou\" and s[-1] in \"aeiou\" for s in words[left:right+1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        hashtable=['a','e','i','o','u']\n",
    "        count=0\n",
    "        for i in range(left,right+1):\n",
    "            lenth=len(words[i])\n",
    "            if words[i][0] in hashtable and words[i][lenth-1] in hashtable:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        res = 0\n",
    "        yuan_list = ['a', 'e', 'i', 'o', 'u']\n",
    "        new_list = words[left:right+1]\n",
    "        for each_word in new_list:\n",
    "            if each_word[0] in yuan_list and each_word[-1] in yuan_list:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowel = \"aeiou\"\n",
    "        vowel_num = 0\n",
    "        for i in words[left:right+1]:\n",
    "            if i[0] in vowel and i[len(i)-1] in vowel:\n",
    "                vowel_num += 1\n",
    "        return vowel_num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowels = (\"a\", \"e\", \"i\", \"o\", \"u\")\n",
    "        ret = 0\n",
    "        for i in range(left, right+1):\n",
    "            if words[i][0] in vowels and words[i][-1] in vowels:\n",
    "                ret += 1\n",
    "        return ret\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        st = {'a', 'e', 'i', 'o','u'}\n",
    "        res = 0\n",
    "        for word in words[left:right+1]:\n",
    "            if word[0] in st and word[-1] in st:\n",
    "                res += 1\n",
    "        return res\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        s = 0\n",
    "        for i in words[left:right+1]:\n",
    "            if (i[0] == 'a' or i[0] == 'e' or i[0] == 'i' or i[0] == 'o' or i[0] == 'u') and (i[-1] == 'a' or i[-1] == 'e' or i[-1] == 'i' or i[-1] == 'o' or i[-1] == 'u'):\n",
    "                s += 1\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowel = ['a','e','i','o','u']\n",
    "        ans = 0\n",
    "        # words2 = words[left:right+1]\n",
    "        for word in words[left:right+1]:\n",
    "            if word[0] in vowel and word[-1] in vowel:\n",
    "                ans += 1\n",
    "        return ans \n",
    "        # return sum(1 for word in vowel if (word[0] in vowel and word[-1] in vowel))\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowels = set(\"aeiou\")\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            word = words[i]\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowels = [0] * 128\n",
    "        vowels[ord('a')] = 1\n",
    "        vowels[ord('e')] = 1\n",
    "        vowels[ord('i')] = 1\n",
    "        vowels[ord('o')] = 1\n",
    "        vowels[ord('u')] = 1\n",
    "        return sum(vowels[ord(w[0])] and vowels[ord(w[-1])] for w in words[left: right + 1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        yuanyin = set(['a','e','i','o','u'])\n",
    "        res = 0\n",
    "        for i in range(left, right+1):\n",
    "            word = words[i]\n",
    "            if word[0] in yuanyin and word[-1] in yuanyin:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, s: List[str], l: int, r: int) -> int:\n",
    "        return sum(1 for x in range(l, r + 1) if s[x][0] in \"aeiou\" and s[x][-1] in \"aeiou\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowels = set(\"aeiou\")\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            word = words[i]\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return sum((words[i][0] in \"aeiou\" and words[i][-1] in \"aeiou\" for i in range(left, right + 1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowels = set(\"aeiou\")\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            word = words[i]\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return sum(\n",
    "            w[0] in 'aeiou' and w[-1] in 'aeiou' for w in words[left:right+1]       \n",
    "            )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        v=0\n",
    "        for i in range(left,right+1):\n",
    "\n",
    "            if words[i][0] in ['a','e','i','o','u'] and words[i][-1] in ['a','e','i','o','u']:\n",
    "                v+=1\n",
    "\n",
    "\n",
    "        return v\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:     \n",
    "        vowels=set(\"aeiou\")\n",
    "        ans=0\n",
    "        for i in range(left,right+1):\n",
    "            word=words[i]\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                ans+=1\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return sum(all(c in \"aeiou\" for c in (s[0], s[-1])) for s in words[left: right + 1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "         return sum(s[0] in \"aeiou\" and s[-1] in \"aeiou\" for s in words[left:right+1])\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowels = set(\"aeiou\")\n",
    "        ans = 0\n",
    "        for i in range(left, right + 1):\n",
    "            word = words[i]\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        count = 0\n",
    "        word = 'aeiou'\n",
    "        for i in range(left,right+1):\n",
    "            if (words[i][0] in word) and (words[i][-1] in word):\n",
    "                count+=1\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        ans = 0\n",
    "        is_valid = [\"a\", \"e\", \"i\", \"o\", \"u\"]\n",
    "        for i, word in enumerate(words):\n",
    "            if word[0] in is_valid and word[-1] in is_valid and (i >= left and i <= right):\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "\n",
    "        newList = words[left: right + 1]\n",
    "\n",
    "        result = 0\n",
    "        temp = ['a', 'e', 'i', 'o', 'u']\n",
    "        for i in newList:\n",
    "            if i[0] in temp and i[-1] in temp:\n",
    "                result += 1\n",
    "        \n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(left,right+1):\n",
    "            word = words[i]\n",
    "            if word[0] in 'aeiou' and word[-1] in 'aeiou':\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return sum(1 for i in range(left, right + 1) if words[i][0] in \"aeiou\" and words[i][-1] in \"aeiou\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return sum(1 for word in words[left:right + 1] if word[0] in \"aeiou\" and word[-1] in \"aeiou\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        answer = 0\n",
    "\n",
    "        while left <= right:\n",
    "            if words[left].startswith(('a','e','i','o','u')):\n",
    "                if words[left].endswith(('a','e','i','o','u')):\n",
    "                    answer += 1\n",
    "\n",
    "            left += 1\n",
    "        \n",
    "        return answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        listNew = []\n",
    "        listYuanyin = ['a','e','i','o','u']\n",
    "        count = 0\n",
    "        for i in range(right-left+1):\n",
    "            listNew.append(words[left+i])\n",
    "        for i in range(len(listNew)):\n",
    "            strTemp = str(listNew[i])\n",
    "            if strTemp[0] in listYuanyin and strTemp[-1] in listYuanyin:\n",
    "                count += 1\n",
    "        return count\n",
    "        \n",
    "\n",
    "\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        count = 0\n",
    "        y = ['a','e','i','o','u']\n",
    "        for word in words[left:right+1]:\n",
    "            if word[0] in y and word[-1] in y:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "vowels = {'a','e','i','o','u'}\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return len([None for w in words[left:right+1] if w[0] in vowels and w[-1] in vowels])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        target = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "        num=0\n",
    "        for i in range(left,right+1):\n",
    "            if words[i][0] in target and words[i][-1] in target:\n",
    "                num += 1\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        s='aeiou'\n",
    "        ans=0\n",
    "        for i in range(left,right+1):\n",
    "            if words[i][0] in s and words[i][-1] in s:\n",
    "                ans+=1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "vowels = [0] * 128\n",
    "vowels[ord('a')] = 1\n",
    "vowels[ord('e')] = 1\n",
    "vowels[ord('i')] = 1\n",
    "vowels[ord('o')] = 1\n",
    "vowels[ord('u')] = 1\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return sum(vowels[ord(w[0])] and vowels[ord(w[-1])] for w in words[left: right + 1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        count = 0\n",
    "        aut = {'a','o','e','i','u'}\n",
    "        for i in range(left,right + 1):\n",
    "            if words[i][0] in aut and words[i][-1] in aut:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        return sum(1 for i in range(left, right + 1) if words[i][0] in \"aeiou\" and words[i][-1] in \"aeiou\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        count = 0\n",
    "        vowel_list = ['a','e','i','o','u']\n",
    "        for word in words[left:right+1]:\n",
    "            if word[0] in vowel_list and word[-1] in vowel_list:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        yyin='aeiou'\n",
    "        sum=0\n",
    "        for i in range(left,right+1):\n",
    "            if words[i][0] in yyin and words[i][-1] in yyin:\n",
    "                sum =sum+1\n",
    "        return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        \n",
    "        ans = 0\n",
    "        vowel_set = set(['a', 'e', 'i', 'o', 'u'])\n",
    "\n",
    "        for i in range(left, right + 1):\n",
    "            if words[i][0] in vowel_set and words[i][-1] in vowel_set:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        res = 0\n",
    "        st = set('aeiou')\n",
    "        for i in range(left, right + 1):\n",
    "            if words[i][0] in st and words[i][-1] in st:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(left,right+1):\n",
    "            if words[i][0] in 'aeiou' and words[i][-1] in 'aeiou':\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "        vowels = \"aeiou\"\n",
    "        return sum([\n",
    "            1 if word[0] in vowels and word[-1] in vowels else 0\n",
    "            for word in words[left : right + 1]\n",
    "        ])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n",
    "\n",
    "        vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "        count = 0\n",
    "    \n",
    "        for i in range(left, right+1):\n",
    "            word = words[i]\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                count += 1\n",
    "    \n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowel = ['a', 'e', 'i', 'o', 'u']\n",
    "        dp = [0] * (len(words) + 1)\n",
    "        res = []\n",
    "        for index, word in enumerate(words):\n",
    "            if word[0] in vowel and word[-1] in vowel:\n",
    "                dp[index + 1] = dp[index] + 1\n",
    "            else:\n",
    "                dp[index + 1] = dp[index]\n",
    "        for query in queries:\n",
    "            l = query[0]\n",
    "            r = query[-1] + 1\n",
    "            res.append(dp[r] - dp[l])\n",
    "\n",
    "        return res\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        def bisectLeft(nums: list[int], target: int) -> int:\n",
    "            left,right=-1,len(nums)\n",
    "            while left+1<right:\n",
    "                mid=(left+right)>>1\n",
    "                if nums[mid]<target: left=mid\n",
    "                else: right=mid\n",
    "            return right\n",
    "\n",
    "        def bisectRight(nums: list[int], target: int) -> int:\n",
    "            left,right=-1,len(nums)\n",
    "            while left+1<right:\n",
    "                mid=(left+right)>>1\n",
    "                if nums[mid]<=target: left=mid\n",
    "                else: right=mid\n",
    "            return right\n",
    "\n",
    "        vowels=list('aeiou')\n",
    "        validIdx=[i for i,w in enumerate(words) if w[0] in vowels and w[-1] in vowels]\n",
    "        return [bisectRight(validIdx,r)-bisectLeft(validIdx,l) for l,r in queries]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowels = (\"a\", \"e\", \"i\", \"o\", \"u\")\n",
    "        nums = []\n",
    "        for word in words:\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                nums.append(1)\n",
    "            else:\n",
    "                nums.append(0)\n",
    "        prefix = [0 for i in range(len(nums)+1)]\n",
    "        for i in range(len(nums)):\n",
    "            if nums[i] == 1:\n",
    "                prefix[i+1] = prefix[i] + 1\n",
    "            else:\n",
    "                prefix[i+1] = prefix[i]\n",
    "        ans = [] \n",
    "        for l, r in queries:\n",
    "            ans.append(prefix[r+1] - prefix[l])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        num=['a','e','i','o','u']\n",
    "        res=[0]*(len(words)+1)\n",
    "        results=[]\n",
    "        for i,word in enumerate(words):\n",
    "            if word[0] in num and word[-1] in num:\n",
    "                res[i+1]=res[i]+1\n",
    "            else:\n",
    "                res[i+1]=res[i]\n",
    "        for l in queries:\n",
    "            results.append(res[l[1]+1]-res[l[0]])\n",
    "        return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        n = len(words)\n",
    "        l = [0] * (n + 1)\n",
    "        for i in range(1, n + 1):\n",
    "            l[i] = l[i - 1]\n",
    "            w = words[i - 1]\n",
    "            if w[0] in 'aeiou' and w[-1] in 'aeiou':\n",
    "                l[i] += 1\n",
    "        \n",
    "        ret = []\n",
    "        for q in queries:\n",
    "            ret.append(l[q[1] + 1] - l[q[0]])\n",
    "\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        cnt = [0]\n",
    "        aset = 'aeiou'  #{'a','e','i','o','u'}\n",
    "        for word in words:\n",
    "            if word[0] in aset and word[-1] in aset:\n",
    "                cnt.append(cnt[-1]+1)\n",
    "            else:\n",
    "                cnt.append(cnt[-1])\n",
    "        ans = []\n",
    "        for i, j in queries:\n",
    "            ans.append(cnt[j+1] - cnt[i])\n",
    "        return ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowels = set(['a', 'e', 'i', 'o', 'u'])\n",
    "        prefix = [0] * (len(words)+1)\n",
    "        for i, word in enumerate(words):\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                prefix[i+1] = prefix[i] + 1\n",
    "            else:\n",
    "                prefix[i+1] = prefix[i]\n",
    "\n",
    "        ans = [0] * len(queries)\n",
    "        for i, q in enumerate(queries):\n",
    "            ans[i] = prefix[q[1]+1] - prefix[q[0]]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        n=len(words)\n",
    "        v=\"aeiou\"\n",
    "        tree=[0]*(n+1)\n",
    "        def lowbit(i):\n",
    "            return i&-i\n",
    "        def update(i,delta):\n",
    "            while i<=n:\n",
    "                tree[i]+=delta\n",
    "                i+=lowbit(i)\n",
    "        def query(i):\n",
    "            t=0\n",
    "            while i:\n",
    "                t+=tree[i]\n",
    "                i-=lowbit(i)\n",
    "            return t\n",
    "        for i, w in enumerate(words):\n",
    "            update(i+1, w[0] in v and w[-1] in v)\n",
    "        #print(tree)\n",
    "        return list(map(lambda x: query(x[1]+1)-query(x[0]), queries))\n",
    "\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        n=len(words)\n",
    "        v=set(\"aeiou\")\n",
    "        tree=[0]*(n+1)\n",
    "        def lowbit(i):\n",
    "            return i&-i\n",
    "        def update(i,delta):\n",
    "            while i<=n:\n",
    "                tree[i]+=delta\n",
    "                i+=lowbit(i)\n",
    "        def query(i):\n",
    "            t=0\n",
    "            while i:\n",
    "                t+=tree[i]\n",
    "                i-=lowbit(i)\n",
    "            return t\n",
    "        for i, w in enumerate(words):\n",
    "            if w[0] in v and w[-1] in v:\n",
    "                update(i+1,1)\n",
    "        #print(tree)\n",
    "        return list(map(lambda x: query(x[1]+1)-query(x[0]), queries))\n",
    "\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        n=len(words)\n",
    "        v=set(\"aeiou\")\n",
    "        tree=[0]*(n+1)\n",
    "        def lowbit(i):\n",
    "            return i&-i\n",
    "        def update(i,delta):\n",
    "            while i<=n:\n",
    "                tree[i]+=delta\n",
    "                i+=lowbit(i)\n",
    "        def query(i):\n",
    "            t=0\n",
    "            while i:\n",
    "                t+=tree[i]\n",
    "                i-=lowbit(i)\n",
    "            return t\n",
    "        for i, w in enumerate(words):\n",
    "            update(i+1, w[0] in v and w[-1] in v)\n",
    "        #print(tree)\n",
    "        return list(map(lambda x: query(x[1]+1)-query(x[0]), queries))\n",
    "\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowels = set(['a', 'e', 'u', 'i', 'o'])\n",
    "        n = len(words)\n",
    "        prefix_sum = [0] * (n + 1)\n",
    "        for i, word in enumerate(words):\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                prefix_sum[i + 1] = prefix_sum[i] + 1\n",
    "            else:\n",
    "                prefix_sum[i + 1] = prefix_sum[i]\n",
    "        ans = []\n",
    "        for l, r in queries:\n",
    "            ans.append(prefix_sum[r + 1] - prefix_sum[l])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        dic = {'a','e','i','o','u'}\n",
    "        def check(s: str) -> bool:\n",
    "            if s[0] in dic and s[-1] in dic:\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "        c = []\n",
    "        pre = 0\n",
    "        c.append(0)\n",
    "        for i,w in enumerate(words):\n",
    "            if check(w):\n",
    "                pre += 1\n",
    "            c.append(pre)\n",
    "        res = []\n",
    "        for i in queries:\n",
    "            t = c[i[1]+1] - c[i[0]]\n",
    "            res.append(t)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        stand_char = set(['a', 'e', 'i', 'o', 'u'])\n",
    "        ans = [0] * (len(words) + 1)\n",
    "        for idx, word in enumerate(words):\n",
    "            if word[0] in stand_char and word[-1] in stand_char:\n",
    "                ans[idx+1] = ans[idx] + 1\n",
    "            else:\n",
    "                ans[idx+1] = ans[idx]\n",
    "        res = []\n",
    "        for left, right in queries:\n",
    "            res.append(ans[right+1]-ans[left])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowel = set('aeiou')\n",
    "        prefixSum = [0]\n",
    "        for word in words:\n",
    "            if word[0] in vowel and word[-1] in vowel:\n",
    "                prefixSum.append(prefixSum[-1] + 1)\n",
    "            else:\n",
    "                prefixSum.append(prefixSum[-1])\n",
    "        res = []\n",
    "        for q in queries:\n",
    "            l, r = q[0], q[1]\n",
    "            res.append(prefixSum[r + 1] - prefixSum[l])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        \"\"\"\n",
    "        前缀和\n",
    "        :param words:\n",
    "        :param queries:\n",
    "        :return:\n",
    "        \"\"\"\n",
    "        res = []\n",
    "        vowel_sum = [0] * (len(words) + 1)\n",
    "        for i, w in enumerate(words):\n",
    "            if self.is_vowel_strings(w):\n",
    "                vowel_sum[i + 1] = vowel_sum[i] + 1\n",
    "            else:\n",
    "                vowel_sum[i + 1] = vowel_sum[i]\n",
    "        print(vowel_sum)\n",
    "        for query in queries:\n",
    "            start, end = query\n",
    "            print(start, end, vowel_sum[start],vowel_sum[end+1])\n",
    "            res.append(vowel_sum[end + 1] - vowel_sum[start])\n",
    "\n",
    "        return res\n",
    "\n",
    "    @staticmethod\n",
    "    def is_vowel_strings(word: str) -> bool:\n",
    "        return word.startswith(('a', 'e', 'i', 'o', 'u')) and word.endswith(('a', 'e', 'i', 'o', 'u'))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        tmp = [0]\n",
    "        n = 0\n",
    "        avail = \"aiueo\"\n",
    "        for word in words:\n",
    "            if word[0] in avail and word[-1] in avail:\n",
    "                n+=1\n",
    "            tmp.append(n)\n",
    "        out = []\n",
    "        for left, right in queries:\n",
    "            print(right)\n",
    "            out.append(tmp[right+1]-tmp[left])\n",
    "        return out\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowels = set(\"aeiou\")\n",
    "        nums = []\n",
    "        result = []\n",
    "        for i,w in enumerate(words):\n",
    "            if w[0] in vowels and w[-1] in vowels:\n",
    "                nums.append(i)\n",
    "        for l,r in queries:\n",
    "            print(l,r)\n",
    "            right = bisect_right(nums, r)\n",
    "            left = bisect_left(nums, l)\n",
    "            count = right - left\n",
    "            result.append(count)\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        pre = list(accumulate([0]+[w[0] in 'aeiou' and w[-1] in 'aeiou'  for w in words]))\n",
    "        return [pre[r+1]-pre[l] for l,r in queries]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        s = list(accumulate((w[0] in \"aeiou\" and w[-1] in \"aeiou\" for w in words), initial=0))\n",
    "        return [s[r + 1] - s[l] for l, r in queries]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        hash_set = {\"a\",\"e\",\"i\",\"o\",\"u\"}\n",
    "        words_len = len(words)\n",
    "        words_count = [0]*(words_len+1)\n",
    "        for index, word in enumerate(words,start=1):\n",
    "            if word[0] in hash_set and word[-1] in hash_set:\n",
    "                words_count[index]=1\n",
    "        for i in range(1, words_len+1):\n",
    "            words_count[i]+=words_count[i-1]\n",
    "        queries_len = len(queries)\n",
    "        ans = [0]*queries_len\n",
    "        for index, (x,y) in enumerate(queries):\n",
    "            ans[index] = words_count[y+1]-words_count[x]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        dic={ 'a', 'e', 'i', 'o', 'u'}\n",
    "        for j in range( len( words)):\n",
    "            if ( words[j][0] in dic) and ( words[j][-1 ] in dic) :\n",
    "                words[j] = 1 \n",
    "            else:\n",
    "                words[j] = 0 \n",
    "        dic= { -1 :0 } \n",
    "        for j in range( len( words)) :\n",
    "            dic[j] = dic[j-1] + words[j]\n",
    "        ans=[ (  dic[j]-dic[i-1]) for i ,j in queries     ]\n",
    "        return ans \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        flags = [0]* len(words)\n",
    "        vowels = ['a','e','i','o','u']\n",
    "        for i,word in enumerate(words):\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                flags[i]=1\n",
    "        res = [0]*len(queries)\n",
    "        n = len(flags)\n",
    "        preSum = [0]*(n+1)\n",
    "        preS = 0\n",
    "        for i,flag in enumerate(flags):\n",
    "            preS+=flag\n",
    "            preSum[i+1]=preS\n",
    "        print(flags)\n",
    "        print(preSum)\n",
    "        for i,query in enumerate(queries):\n",
    "            print(query[1],query[0])\n",
    "            res[i]=preSum[query[1]+1]-preSum[query[0]]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        chars = {'a', 'e', 'i', 'o', 'u'}\n",
    "        counts = [0 for _ in range(len(words))]\n",
    "        for i, w in enumerate(words):\n",
    "            if w[0] in chars and w[-1] in chars:\n",
    "                counts[i] = counts[i - 1] + 1 if i > 0 else 1\n",
    "            else:\n",
    "                counts[i] = counts[i - 1] if i > 0 else 0\n",
    "        result = []\n",
    "        for q in queries:\n",
    "            if q[0] > 0:\n",
    "                result.append(counts[q[1]] - counts[q[0] - 1])\n",
    "            else:\n",
    "                result.append(counts[q[1]])\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowel = set(\"aeiou\")\n",
    "        cnt = [0]\n",
    "        num = 0\n",
    "        ans = []\n",
    "        for i in words:\n",
    "            if i[0] in vowel and i[-1] in vowel:\n",
    "                num += 1\n",
    "            cnt.append(num)\n",
    "        # print(cnt)\n",
    "        for a,b in queries:\n",
    "            ans.append(cnt[b+1] - cnt[a])\n",
    "        return ans\n",
    "        # print(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        a,s=[],[]\n",
    "        k=0\n",
    "        for i in words:\n",
    "            if i[0] in \"aeiou\" and i[-1]in \"aeiou\":\n",
    "                k+=1\n",
    "                a.append(k)\n",
    "            else:\n",
    "                a.append(k)\n",
    "        a.insert(0,0)\n",
    "        for b1,b2 in queries:\n",
    "            i = a[b2+1]-a[b1]\n",
    "            s.append(i)\n",
    "        return(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        #用前缀和求解\n",
    "        w_len = len(words)\n",
    "        q_len = len(queries)\n",
    "        match_list = [0] * (w_len+1)\n",
    "        vowel_list = ['a', 'e', 'i', 'o', 'u']\n",
    "        answer = []\n",
    "        for i in range(w_len):\n",
    "            if words[i][0] in vowel_list and words[i][-1] in vowel_list:\n",
    "                match_list[i+1] = match_list[i] + 1\n",
    "            else:\n",
    "                match_list[i+1] = match_list[i]\n",
    "        #print(\"match_list = \", match_list)\n",
    "        for i, j in queries:\n",
    "            temp_sum = match_list[j+1] - match_list[i]\n",
    "            answer.append(temp_sum)\n",
    "        #print(answer)\n",
    "        return answer\n",
    "        \"\"\"\n",
    "        超出时间限制\n",
    "        w_len = len(words)\n",
    "        q_len = len(queries)\n",
    "        match_list = []\n",
    "        vowel_list = ['a', 'e', 'i', 'o', 'u']\n",
    "        answer = []\n",
    "        for i in range(w_len):\n",
    "            if words[i][0] in vowel_list and words[i][-1] in vowel_list:\n",
    "                match_list.append(1)\n",
    "            else:\n",
    "                match_list.append(0)\n",
    "        #print(\"match_list = \", match_list)\n",
    "        for i, j in queries:\n",
    "            temp_sum = 0\n",
    "            for k in range(i, j+1):\n",
    "                temp_sum += match_list[k]\n",
    "            answer.append(temp_sum)\n",
    "        #print(answer)\n",
    "        return answer\n",
    "        \"\"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowel = {'a','e','i','o','u'}\n",
    "        countlist ,coun= [0] * (len(words)+1) , 0\n",
    "        for i in range(len(words)):\n",
    "            if words[i][0] in vowel and words[i][-1] in vowel:\n",
    "                coun += 1\n",
    "                countlist[i] = coun\n",
    "            else:\n",
    "                countlist[i] = coun\n",
    "        ans = []\n",
    "        for i in range(len(queries)):\n",
    "            ans.append(countlist[queries[i][1]] - countlist[queries[i][0]-1])\n",
    "           \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "VOWEL = 'aeiou'\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        # 前缀和\n",
    "        prefix = [0]\n",
    "        for w in words:\n",
    "            v = w[0] in VOWEL and w[-1] in VOWEL\n",
    "            prefix.append(prefix[-1] + v)\n",
    "        for i, (l, r) in enumerate(queries):\n",
    "            queries[i] = prefix[r+1] - prefix[l]\n",
    "        return queries\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        n = len(words)\n",
    "        d = set(['a', 'e', 'i', 'o', 'u'])\n",
    "        pre = (n+1) * [0]\n",
    "        for i in range(n):\n",
    "            if words[i][0] in d and words[i][-1] in d:\n",
    "                pre[i+1] = pre[i] + 1\n",
    "            else:\n",
    "                pre[i+1] = pre[i]\n",
    "        res = []\n",
    "        for i in range(len(queries)):\n",
    "            l, r= queries[i]\n",
    "            res.append(pre[r+1]-pre[l])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        n = len(words)\n",
    "        pre = [0] * (n+1)\n",
    "        cnt = 0\n",
    "        for i, word in enumerate(words):\n",
    "            if word[0] in 'aeiou' and word[-1] in 'aeiou':\n",
    "                cnt += 1\n",
    "                pre[i+1] = cnt\n",
    "            else:\n",
    "                pre[i+1] = pre[i]\n",
    "\n",
    "        res = []\n",
    "        for q in queries:\n",
    "            res.append(pre[q[1]+1]-pre[q[0]])\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution():\n",
    "\tdef vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "\t\tn=len(words)\n",
    "\t\taf=[0]*(n+1)\n",
    "\t\tf=0\n",
    "\t\tletters=set(\"aeiou\")\n",
    "\t\tfor i in range(len(words)):\n",
    "\t\t\tif words[i][0] in letters and words[i][-1] in letters:\n",
    "\t\t\t\tf+=1\n",
    "\t\t\taf[i]=f\n",
    "\t\tans=[]\n",
    "\t\tfor q in queries:\n",
    "\t\t\tans.append(af[q[1]]-af[q[0]-1])\n",
    "\t\treturn ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        dic = {'a','e','i','o','u'}\n",
    "        def check(s: str) -> bool:\n",
    "            if s[0] in dic and s[-1] in dic:\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "        c = []\n",
    "        pre = 0\n",
    "        c.append(0)\n",
    "        for i,w in enumerate(words):\n",
    "            if check(w):\n",
    "                pre += 1\n",
    "            c.append(pre)\n",
    "        res = []\n",
    "        for i in queries:\n",
    "            t = c[i[1]+1] - c[i[0]]\n",
    "            res.append(t)\n",
    "        print (c)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        yl=list('aeiou')\n",
    "        cw=[1 if words[0][0]in yl and words[0][-1] in yl else 0]\n",
    "        for i in words[1:]:\n",
    "            if i[0] in yl and i[-1] in yl:\n",
    "                cw.append(cw[-1]+1)\n",
    "            else:\n",
    "                cw.append(cw[-1])\n",
    "        return [cw[i[1]]-(cw[i[0]-1] if i[0]!=0 else 0) for i in queries]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        prefix_sums = []\n",
    "        counter = 0\n",
    "        for i in words:\n",
    "            if i.startswith(('a', 'e', 'i', 'o', 'u')) and i.endswith(('a', 'e', 'i', 'o', 'u')):\n",
    "                counter += 1\n",
    "            prefix_sums.append(counter)\n",
    "        result = []\n",
    "        for i in queries:\n",
    "            if i[0] == 0:\n",
    "                start_vowel_num = 0\n",
    "            else:\n",
    "                start_vowel_num = prefix_sums[i[0] - 1]\n",
    "            result.append(prefix_sums[i[1]] - start_vowel_num)\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        dic = [0] * (len(words) + 1)\n",
    "        for i in range(1, len(words) + 1):\n",
    "            if self.isVowel(words[i - 1][0]) and self.isVowel(words[i - 1][-1]):\n",
    "                dic[i] = dic[i - 1] + 1\n",
    "            else:\n",
    "                dic[i] = dic[i - 1]\n",
    "        res = [0] * len(queries)\n",
    "        for i in range(len(queries)):\n",
    "            s, e = queries[i]\n",
    "            res[i] = dic[min(len(dic) - 1, e + 1)] - dic[s]\n",
    "    \n",
    "        return res\n",
    "\n",
    "    def isVowel(self, ch):\n",
    "        return ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowel = set(['a', 'e', 'i', 'o', 'u'])\n",
    "        ret = []\n",
    "\n",
    "        prefixSums = [0]\n",
    "        prefixSum = 0\n",
    "        for word in words:\n",
    "            if word[0] in vowel and word[-1] in vowel:\n",
    "                prefixSum += 1\n",
    "            prefixSums.append(prefixSum)\n",
    "        \n",
    "        for query in queries:\n",
    "            l, r = query\n",
    "            ret.append(prefixSums[r+1] - prefixSums[l])\n",
    "\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        nums = [0] * len(words)\n",
    "        tag = 0\n",
    "        res = [0] * (len(queries) + 1)\n",
    "        vowel = ['a', 'e', 'i', 'o', 'u']\n",
    "\n",
    "        for i,word in enumerate(words):\n",
    "            if word[0] in vowel and word[-1] in vowel:\n",
    "                tag += 1\n",
    "                # print(i, word)\n",
    "            nums[i] = tag\n",
    "        # print(\"nums\", nums)\n",
    "\n",
    "        for i,query in enumerate(queries):\n",
    "            # print(i,query, nums[query[0]:query[1]+1])\n",
    "            if query[1] == query[0] or nums[query[0]+1] == nums[query[0]+1]:\n",
    "                res[i+1] = nums[query[0]] - nums[query[0]-1]\n",
    "            if query[0] == 0:\n",
    "                res[i+1] = nums[0]\n",
    "            res[i+1] += nums[query[1]] - nums[query[0]]\n",
    "\n",
    "        return res[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        o = set([\"a\", \"e\", \"i\", \"o\", \"u\"])\n",
    "        p = [word[0] in o and word[-1] in o for word in words]\n",
    "        presum = list(accumulate(p, initial=0))\n",
    "        ans = []\n",
    "        for x, y in queries:\n",
    "            ans.append(presum[y+1]-presum[x])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        nums = [w[0] in 'aeiou' and w[-1] in 'aeiou' for w in words]\n",
    "        pre = list(accumulate(nums, initial=0))\n",
    "        def query(i, j):\n",
    "            return pre[j+1] - pre[i]\n",
    "        return [query(i, j) for i, j in queries]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        def isVowelString(word):\n",
    "            return isVowelLetter(word[0]) and isVowelLetter(word[-1])\n",
    "\n",
    "        def isVowelLetter(c):\n",
    "            return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u'\n",
    "\n",
    "        n = len(words)\n",
    "        prefix_sums = [0] * (n + 1)\n",
    "        for i in range(n):\n",
    "            value = 1 if isVowelString(words[i]) else 0\n",
    "            prefix_sums[i + 1] = prefix_sums[i] + value\n",
    "        ans = []\n",
    "        for i in range(len(queries)):\n",
    "            start, end = queries[i]\n",
    "            ans.append(prefix_sums[end + 1] - prefix_sums[start])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        str_vowel = 'aeiou'\n",
    "        res = []\n",
    "        # for k in range(0, len(queries)):\n",
    "        #     vow_num = 0\n",
    "        #     for i in range(queries[k][0], queries[k][1]+1):\n",
    "        #         if str_vowel.find(words[i][0]) > -1 and str_vowel.find(words[i][-1]) > -1:\n",
    "        #             vow_num += 1\n",
    "        #     res.append(vow_num)\n",
    "        prefix_sum = [0] * (len(words)+1)\n",
    "        for i in range(len(words)):\n",
    "            if str_vowel.find(words[i][0]) > -1 and str_vowel.find(words[i][-1]) > -1:\n",
    "                prefix_sum[i+1] += prefix_sum[i] + 1\n",
    "            else:\n",
    "                prefix_sum[i+1] += prefix_sum[i]\n",
    "        for i in range(0, len(queries)):\n",
    "            start, end = queries[i]\n",
    "            res.append(prefix_sum[end+1] - prefix_sum[start])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        yuanyin_char = ['a', 'e', 'i', 'o', 'u']\n",
    "        # is_yuanyin = [0]\n",
    "        # for word in words:\n",
    "        #     if word[0] in yuanyin_char and word[-1] in yuanyin_char:\n",
    "        #         is_yuanyin.append(is_yuanyin[-1]+1)\n",
    "        #     else:\n",
    "        #         is_yuanyin.append(is_yuanyin[-1])\n",
    "        is_yuanyin = list(accumulate((int(word[0] in yuanyin_char and word[-1] in yuanyin_char) for word in words), initial=0))\n",
    "        results = []\n",
    "        for query in queries:\n",
    "            results.append(is_yuanyin[query[1]+1] - is_yuanyin[query[0]])\n",
    "        return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowels = set(\"aeiou\")\n",
    "        s = list(accumulate((int(w[0] in vowels and w[-1] in vowels) for w in words), initial=0))\n",
    "        return [s[r + 1] - s[l] for l, r in queries]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        presum = [1 if w[0] in 'aeiou' and w[-1] in 'aeiou' else 0 for w in words]\n",
    "        for i in range(1, len(presum)):\n",
    "            presum[i] += presum[i - 1]\n",
    "        presum.append(0)  # presum[-1] == 0\n",
    "        \n",
    "        return [presum[q[1]] - presum[q[0] - 1] for q in queries]          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        def isVowelString(word):\n",
    "            return isVowelLetter(word[0]) and isVowelLetter(word[-1])\n",
    "\n",
    "        def isVowelLetter(c):\n",
    "            return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u'\n",
    "\n",
    "        n = len(words)\n",
    "        prefix_sums = [0] * (n + 1)\n",
    "        for i in range(n):\n",
    "            value = 1 if isVowelString(words[i]) else 0\n",
    "            prefix_sums[i + 1] = prefix_sums[i] + value\n",
    "        ans = []\n",
    "        for i in range(len(queries)):\n",
    "            start, end = queries[i]\n",
    "            ans.append(prefix_sums[end + 1] - prefix_sums[start])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        n = len(words)\n",
    "        pre = list(map(int, [w[0] in \"aeiou\" and w[-1] in \"aeiou\" for w in words]))\n",
    "        for i in range(1, n):\n",
    "            pre[i] += pre[i - 1]\n",
    "        ans = []\n",
    "        for l, r in queries:\n",
    "            ans.append(pre[r] - (pre[l - 1] if l > 0 else 0))\n",
    "            # ans.append(sum(pre[l:r + 1]))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        \"\"\"\n",
    "        转化成前缀和\n",
    "        \"\"\"\n",
    "        vowel = 'aeuio'\n",
    "        s=[0]\n",
    "        for i in range(len(words)):\n",
    "            x = int(words[i][0] in vowel and words[i][-1] in vowel)\n",
    "            s.append(s[-1]+x)\n",
    "        ans =[]\n",
    "        for l,r in queries:\n",
    "            ans.append(s[r+1]-s[l])\n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        dp = [0]\n",
    "        res = []\n",
    "        for w in words:\n",
    "            dp.append(dp[-1] + (1 if w[0] in 'aeiou' and w[-1] in 'aeiou' else 0))\n",
    "        for a, b in queries:\n",
    "            res.append(dp[b+1] - dp[a])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "'''\n",
    "[0,3,2,0,,1]\n",
    "[0,0,3,5,5,6]\n",
    "'''\n",
    "\n",
    "class Solution(object):\n",
    "    def vowelStrings(self, words, queries):\n",
    "        arr=[0]\n",
    "        ans=[]\n",
    "        for i in words:\n",
    "            x=int(i[0] in \"aeiou\" and i[-1] in \"aeiou\")\n",
    "            arr.append(arr[-1]+x)\n",
    "        for l,r in queries:\n",
    "            ans.append(arr[r+1]-arr[l])\n",
    "        return ans\n",
    "\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        def check(c):\n",
    "            return c=='a' or c=='e' or c=='i' or c=='o' or c=='u'\n",
    "        def checkword(word):\n",
    "            return check(word[0]) and check(word[-1])\n",
    "\n",
    "        n=len(words)\n",
    "        pre=[0]*(n+1)\n",
    "        for i in range(len(words)):\n",
    "            if checkword(words[i]):\n",
    "                value=1\n",
    "            else:\n",
    "                value=0\n",
    "            pre[i+1]=pre[i]+value\n",
    "        ans=[]\n",
    "        for st,ed in queries:\n",
    "            ans.append((pre[ed+1]-pre[st]))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def check_is_vowel(self, word):\n",
    "        check_set = ('a', 'e', 'i', 'o', 'u')\n",
    "        flag_top = word[0].lower() in check_set\n",
    "        flag_bottom = word[-1].lower() in check_set\n",
    "        return flag_top and flag_bottom\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        n = len(words)\n",
    "        pre_sum = [0 for _ in range(n + 1)]\n",
    "        for i in range(1, n + 1):\n",
    "            if self.check_is_vowel(words[i - 1]):\n",
    "                value = 1\n",
    "            else:\n",
    "                value = 0\n",
    "            pre_sum[i] = pre_sum[i - 1] + value\n",
    "        res = []\n",
    "        for start, end in queries:\n",
    "            res.append(pre_sum[end + 1] - pre_sum[start])\n",
    "        return res\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        def isVowelString(word):\n",
    "            return isVowelLetter(word[0]) and isVowelLetter(word[-1])\n",
    "\n",
    "        def isVowelLetter(c):\n",
    "            return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u'\n",
    "\n",
    "        n = len(words)\n",
    "        prefix_sums = [0] * (n + 1)\n",
    "        for i in range(n):\n",
    "            value = 1 if isVowelString(words[i]) else 0\n",
    "            prefix_sums[i + 1] = prefix_sums[i] + value\n",
    "        ans = []\n",
    "        for i in range(len(queries)):\n",
    "            start, end = queries[i]\n",
    "            ans.append(prefix_sums[end + 1] - prefix_sums[start])\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "\n",
    "        n = len(words)\n",
    "\n",
    "        pres = []\n",
    "\n",
    "        for i in words:\n",
    "            if i[0] in 'aeiou' and i[-1] in 'aeiou':\n",
    "                pres.append(1)\n",
    "            else:\n",
    "                pres.append(0)\n",
    "                \n",
    "        for i in range(1,n):\n",
    "            pres[i] += pres[i-1]\n",
    "            \n",
    "        res = []\n",
    "\n",
    "        for x, y in queries:\n",
    "            if x == 0:\n",
    "                res.append(pres[y])\n",
    "            else:\n",
    "                res.append(pres[y] - pres[x-1])\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        n = len(words)\n",
    "        p=prefix_sums = [0]*(n + 1)\n",
    "        for i,ss in enumerate(words):\n",
    "            p[i + 1] = p[i] + (ss[0] in 'aeiou' and ss[-1] in 'aeiou')\n",
    "        \n",
    "        return [p[end + 1] - p[a]  for a,end in queries]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        prefixSum = [0] * (len(words) + 1)\n",
    "        for i,word in enumerate(words):\n",
    "            val = 0\n",
    "            if self.isVowelString(word):\n",
    "                val = 1\n",
    "            prefixSum[i+1] = prefixSum[i] + val\n",
    "\n",
    "        res = []\n",
    "        for query in queries:\n",
    "            l,r = query[0],query[1]\n",
    "            res.append(prefixSum[r+1] - prefixSum[l])\n",
    "        return res\n",
    "\n",
    "\n",
    "    def isVowelString(self, s: str) -> bool:\n",
    "        c1 = s[0]\n",
    "        c2 = s[len(s)-1]\n",
    "        return self.isVowelChar(c1) and self.isVowelChar(c2)\n",
    "\n",
    "    def isVowelChar(self, c: str) -> bool:\n",
    "        if c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u':\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def check(self, in_str):\n",
    "        yuanyin = ['a','e','i','o','u']\n",
    "        if in_str[0] in yuanyin and in_str[-1] in yuanyin:\n",
    "            return 1\n",
    "        return 0\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        # 记录每一个位置之后用sum时间复杂度就是n+nm，改为记录每个位置前缀和 长度为n+1\n",
    "        # in_yuanyin_list = [0] * len(words)\n",
    "        # res_list = []\n",
    "        # for index, i in enumerate(words):\n",
    "        #     if self.check(i) is True:\n",
    "        #         in_yuanyin_list[index] = 1\n",
    "        # # print(in_yuanyin_list)\n",
    "        # for i in queries:\n",
    "        #     res_list.append(sum(in_yuanyin_list[i[0]:i[1]+1]))\n",
    "        # return res_list\n",
    "        qianzhui_list = [0] * (len(words)+1)\n",
    "        \n",
    "        res_list = []\n",
    "        for index, i in enumerate(words):\n",
    "           qianzhui_list[index+1] = qianzhui_list[index] + self.check(i)\n",
    "        print(qianzhui_list) \n",
    "        for i in queries:\n",
    "            # 第i位置前面有qianzhui_list[i]个 如果要包括i位置就是i+1\n",
    "            res_list.append(qianzhui_list[i[1]+1]-qianzhui_list[i[0]])\n",
    "        return res_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        str_vowel = 'aeiou'\n",
    "        vowel_dict = defaultdict(int)\n",
    "        res = []\n",
    "        # for k in range(0, len(queries)):\n",
    "        #     vow_num = 0\n",
    "        #     for i in range(queries[k][0], queries[k][1]+1):\n",
    "        #         if str_vowel.find(words[i][0]) > -1 and str_vowel.find(words[i][-1]) > -1:\n",
    "        #             vow_num += 1\n",
    "        #     res.append(vow_num)\n",
    "        prefix_sum = [0] * (len(words)+1)\n",
    "        for i in range(len(words)):\n",
    "            if str_vowel.find(words[i][0]) > -1 and str_vowel.find(words[i][-1]) > -1:\n",
    "                prefix_sum[i+1] += prefix_sum[i] + 1\n",
    "            else:\n",
    "                prefix_sum[i+1] += prefix_sum[i]\n",
    "        # print(vowel_dict)\n",
    "        for i in range(0, len(queries)):\n",
    "            start, end = queries[i]\n",
    "            res.append(prefix_sum[end+1] - prefix_sum[start])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class SegmentTree:\n",
    "    def __init__(self, items):\n",
    "        self.real_size = len(items) \n",
    "        i = 0\n",
    "        while (2 << i) < self.real_size:\n",
    "            i += 1\n",
    "        \n",
    "        self.sp_size = (2 << (i + 1))\n",
    "        self.leves_size = (2 << i)\n",
    "\n",
    "        self.info = [0] * self.sp_size\n",
    "\n",
    "        # self.t = 0\n",
    "        \n",
    "        for i in range(len(items)):\n",
    "            self.initial(items[i], i, i, 0, 0, self.leves_size - 1)\n",
    "        \n",
    "\n",
    "    \n",
    "    def initial(self, val, tleft, tright, idx, cleft, cright):\n",
    "        # self.t += 1\n",
    "        # print(val, tleft, tright, idx, cleft, cright)\n",
    "        # if self.t >= 20:\n",
    "        #     return 0\n",
    "\n",
    "        if tleft == cleft and tright == cright:\n",
    "            self.info[idx] = val \n",
    "            return\n",
    "        \n",
    "        lidx = (idx << 1) | 1\n",
    "        ridx = lidx + 1\n",
    "\n",
    "        cmid = (cleft + cright) >> 1\n",
    "        \n",
    "        if tleft > cmid:\n",
    "            self.initial(val, tleft, tright, ridx, cmid + 1, cright)\n",
    "        else:\n",
    "            self.initial(val, tleft, tright, lidx, cleft, cmid)\n",
    "\n",
    "        self.info[idx] += val\n",
    "    \n",
    "    def search(self, tleft, tright, idx, cleft, cright):\n",
    "        if tleft <= cleft and tright >= cright:\n",
    "            return self.info[idx]\n",
    "        \n",
    "        lidx = (idx << 1) | 1\n",
    "        ridx = lidx + 1\n",
    "\n",
    "        cmid = (cleft + cright) >> 1\n",
    "        \n",
    "        lval = 0\n",
    "        if cmid >= tleft:\n",
    "            lval = self.search(tleft, tright, lidx, cleft, cmid)\n",
    "        \n",
    "        rval = 0\n",
    "        if cmid < tright:\n",
    "            rval = self.search(tleft, tright, ridx, cmid + 1, cright)\n",
    "        \n",
    "        return lval + rval\n",
    "        \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowel = [0] * len(words)\n",
    "\n",
    "        for i in range(len(words)):\n",
    "            if words[i][0] in ('a', 'e', 'i', 'o', 'u') \\\n",
    "            and words[i][-1] in ('a', 'e', 'i', 'o', 'u'):\n",
    "                vowel[i] = 1\n",
    "        \n",
    "        for i in range(1, len(words)):\n",
    "            vowel[i] += vowel[i - 1]\n",
    "        \n",
    "        res = []\n",
    "        for x, y in queries:\n",
    "            if x > 0:\n",
    "                res.append(vowel[y] - vowel[x - 1])\n",
    "            else:\n",
    "                res.append(vowel[y])\n",
    "        \n",
    "        return res\n",
    "\n",
    "\n",
    "\n",
    "        # 线段树，效率慢些\n",
    "        vowel = [0] * len(words)\n",
    "\n",
    "        for i in range(len(words)):\n",
    "            if words[i][0] in ('a', 'e', 'i', 'o', 'u') \\\n",
    "            and words[i][-1] in ('a', 'e', 'i', 'o', 'u'):\n",
    "                vowel[i] = 1\n",
    "        \n",
    "        # print(vowel)\n",
    "        st = SegmentTree(vowel)\n",
    "\n",
    "        res = []\n",
    "\n",
    "        for x, y in queries:\n",
    "            res.append(st.search(x, y, 0, 0, st.leves_size - 1))\n",
    "        \n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        def isVowelString(word):\n",
    "            return isVowelLetter(word[0]) and isVowelLetter(word[-1])\n",
    "\n",
    "        def isVowelLetter(c):\n",
    "            return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u'\n",
    "\n",
    "        n = len(words)\n",
    "        prefix_sums = [0] * (n + 1)\n",
    "        for i in range(n):\n",
    "            value = 1 if isVowelString(words[i]) else 0\n",
    "            prefix_sums[i + 1] = prefix_sums[i] + value\n",
    "        ans = []\n",
    "        for i in range(len(queries)):\n",
    "            start, end = queries[i]\n",
    "            ans.append(prefix_sums[end + 1] - prefix_sums[start])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        presum = list(accumulate((w[0] in \"aeiou\" and w[-1] in \"aeiou\" for w in words), initial=0))\n",
    "        print(presum)\n",
    "        return [presum[i[1]+1] - presum[i[0]] for i in queries]\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        univoc = ['a', 'e', 'i', 'o', 'u']\n",
    "        ans = []\n",
    "        signal = [0]\n",
    "        \n",
    "        for word in words:\n",
    "            if word[0] in univoc and word[-1] in univoc:\n",
    "                signal.append(1 + signal[-1])\n",
    "            else:\n",
    "                signal.append(0 + signal[-1])\n",
    "        print(signal)\n",
    "        for l, r in queries:\n",
    "            ans.append(signal[r+1] - signal[l])\n",
    "        return ans\n",
    "        \n",
    "        \n",
    "\n",
    "\n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        s = list(accumulate((w[0] in \"aeiou\" and w[-1] in \"aeiou\" for w in words), initial=0))\n",
    "        return [s[r + 1] - s[l] for l, r in queries]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowels = {'a','e','i','o','u'}\n",
    "        prefixSumArr = [0]\n",
    "        for (i, w) in enumerate(words):\n",
    "            temp = 1 if w[0] in vowels and w[len(w)-1] in vowels else 0\n",
    "            prefixSumArr.append(prefixSumArr[i] + temp)\n",
    "        def myfunc(x):\n",
    "            a,b = x\n",
    "            return prefixSumArr[b+1] - prefixSumArr[a]\n",
    "        res = map(myfunc, queries)\n",
    "        return list(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        def isVowelString(word):\n",
    "            return isVowelLetter(word[0]) and isVowelLetter(word[-1])\n",
    "\n",
    "        def isVowelLetter(c):\n",
    "            return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u'\n",
    "\n",
    "        n = len(words)\n",
    "        prefix_sums = [0] * (n + 1)\n",
    "        for i in range(n):\n",
    "            value = 1 if isVowelString(words[i]) else 0\n",
    "            prefix_sums[i + 1] = prefix_sums[i] + value\n",
    "\n",
    "        ans = []\n",
    "        for i in range(len(queries)):\n",
    "            start, end = queries[i]\n",
    "            ans.append(prefix_sums[end + 1] - prefix_sums[start])\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        pre = [0]\n",
    "        for i in words:\n",
    "            pre.append(int(i[0] in \"aeiou\" and i[-1] in \"aeiou\") + pre[-1])\n",
    "        res = []\n",
    "        for i, j in queries:\n",
    "            res.append(pre[j + 1] - pre[i])\n",
    "        return res\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        n = len(words)\n",
    "        vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "        tag = [0] * n\n",
    "        for idx, word in enumerate(words):\n",
    "            if word[0] in vowels and word[-1] in vowels:\n",
    "                tag[idx] = 1\n",
    "        preSum = [0] * (n+1)\n",
    "        for i in range(1, n +1):\n",
    "            preSum[i] = preSum[i - 1] + tag[i - 1]\n",
    "        m = len(queries)\n",
    "        ans = [0] * m\n",
    "        for idx, [s, e] in enumerate(queries):\n",
    "            ans[idx] = preSum[e + 1] - preSum[s]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "\n",
    "        def isVowel_Start_End(word:str):\n",
    "            if word[0]=='a' or word[0]=='e' or word[0]=='i' or word[0]=='o' or word[0]=='u':\n",
    "                if word[-1]=='a' or word[-1]=='e' or word[-1]=='i' or word[-1]=='o' or word[-1]=='u':\n",
    "                    return True\n",
    "            return False\n",
    "\n",
    "        # minQuery=len(words)-1\n",
    "        # maxQuery=0\n",
    "        # for query in queries:\n",
    "        #     if query[0]<minQuery:\n",
    "        #         minQuery=query[0]\n",
    "        #     if query[1]>maxQuery:\n",
    "        #         maxQuery=query[1]\n",
    "\n",
    "        counts=[]\n",
    "        # for _ in range(minQuery,maxQuery+1):\n",
    "        #     if isVowel_Start_End(words[_]):\n",
    "        for word in words:\n",
    "            if isVowel_Start_End(word):\n",
    "                counts.append(1)\n",
    "            else:\n",
    "                counts.append(0)\n",
    "        sum=[0]\n",
    "        for count in counts:\n",
    "            sum.append(sum[-1]+count)\n",
    "        answer=[]\n",
    "        for query in queries:\n",
    "            # answer.append(sum[query[1]+1-minQuery]-sum[query[0]-minQuery])\n",
    "            answer.append(sum[query[1]+1]-sum[query[0]])\n",
    "        return answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        pre = [1 if w[0] in 'aeiou' and w[-1] in 'aeiou' else 0 for i, w in enumerate(words)]\n",
    "        s = list(accumulate(pre, initial=0))\n",
    "        # print(s)\n",
    "        res = []\n",
    "        for i, j in queries:\n",
    "            res.append(s[j + 1] - s[i])\n",
    "        return res\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        nums = []\n",
    "        for word in words:\n",
    "            if(word[0] in ('a','e','i','o','u') and word[-1] in ('a','e','i','o','u')):\n",
    "                nums.append(1)\n",
    "            else:\n",
    "                nums.append(0)\n",
    "        presum = [0]\n",
    "        for num in nums:\n",
    "            presum.append(presum[-1]+num)\n",
    "        result = []\n",
    "        for l,r in queries:\n",
    "            result.append(presum[r+1]-presum[l])\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        nums = []\n",
    "        for s in words:\n",
    "            if s[0] in 'aeiou' and s[-1] in 'aeiou':\n",
    "                nums.append(1)\n",
    "            else:\n",
    "                nums.append(0)\n",
    "            \n",
    "        s = list(accumulate(nums, initial = 0))\n",
    "        res = []\n",
    "        for x, y in queries:\n",
    "            res.append(s[y + 1] - s[x])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        pre = [1 if w[0] in 'aeiou' and w[-1] in 'aeiou' else 0 for i, w in enumerate(words)]\n",
    "        s = [0] + list(accumulate(pre))\n",
    "        # print(s)\n",
    "        res = []\n",
    "        for i, j in queries:\n",
    "            res.append(s[j+1] - s[i])\n",
    "        return res\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        vowel={'a','e','i','o','u'}\n",
    "        vowelWords=[(1 if (word[0] in vowel and word[-1] in vowel) else 0) for word in words]\n",
    "        sums=[0]\n",
    "        for word in vowelWords:\n",
    "            sums.append(sums[-1]+word)\n",
    "        return [sums[query[-1]+1]-sums[query[0]] for query in queries]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class PrefixSum:\n",
    "    def __init__(self, array):\n",
    "        self.a = [i for i in array]\n",
    "        self.x = len(array)\n",
    "        for i in range(self.x):\n",
    "            if i: self.a[i] += self.a[i - 1]\n",
    "    def q(self, i, j): \n",
    "        # sum[i:j + 1]\n",
    "        return self.a[j] - (0 if i == 0 else self.a[i - 1])\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        y = 'aeiou'\n",
    "        w = [w[0] in y and w[-1] in y for w in words]\n",
    "        \n",
    "        ps = PrefixSum(w)\n",
    "        \n",
    "        return [ps.q(x, y) for x, y in queries]\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        nums=[1 if word[0] in \"aeiou\" and word[-1] in \"aeiou\" else 0 for word in words]\n",
    "        prefix=list(accumulate(nums))\n",
    "        prefix=[0]+prefix\n",
    "        return [prefix[y+1]-prefix[x] for x,y in queries]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getFlag(self,s):\n",
    "        if s[0] in ['a','e','i','o','u'] and s[-1] in ['a','e','i','o','u']:\n",
    "            return True\n",
    "        return False\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        # words_flag = []\n",
    "        #直接计算sum值会超时，计算前缀和\n",
    "        pre_sum = [0]\n",
    "        for w in words:\n",
    "            tmp = 1 if self.getFlag(w) else 0\n",
    "            pre_sum.append(pre_sum[-1]+tmp)\n",
    "        ans = []\n",
    "        # 在线\n",
    "        for i,j in queries:\n",
    "            ans.append(pre_sum[j+1]-pre_sum[i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        s = list(accumulate((w[0] in \"aeiou\" and w[-1] in \"aeiou\" for w in words), initial=0))\n",
    "        return [s[r + 1] - s[l] for l, r in queries]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        def isVowelString(word):\n",
    "            return isVowelLetter(word[0]) and isVowelLetter(word[-1])\n",
    "\n",
    "        def isVowelLetter(c):\n",
    "            return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u'\n",
    "\n",
    "        n = len(words)\n",
    "        prefix_sums = [0] * (n + 1)\n",
    "        for i in range(n):\n",
    "            value = 1 if isVowelString(words[i]) else 0\n",
    "            prefix_sums[i + 1] = prefix_sums[i] + value\n",
    "        ans = []\n",
    "        for i in range(len(queries)):\n",
    "            start, end = queries[i]\n",
    "            ans.append(prefix_sums[end + 1] - prefix_sums[start])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        nums = [0 for i in range(len(words))]\n",
    "        vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "        for i in range(len(words)):\n",
    "            if words[i][0] in vowels and words[i][-1] in vowels:\n",
    "                nums[i] = 1\n",
    "        acc = [0 for i in range(len(words)+1)]\n",
    "        for i in range(1, len(words)+1):\n",
    "            acc[i] = acc[i-1] + nums[i-1]\n",
    "        print(acc)\n",
    "        ans = []\n",
    "        for i in queries:\n",
    "            ans.append(acc[i[1]+1] - acc[i[0]])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        def isVowelString(word):\n",
    "            return isVowelLetter(word[0]) and isVowelLetter(word[-1])\n",
    "\n",
    "        def isVowelLetter(c):\n",
    "            return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u'\n",
    "\n",
    "        n = len(words)\n",
    "        prefix_sums = [0] * (n + 1)\n",
    "        for i in range(n):\n",
    "            value = 1 if isVowelString(words[i]) else 0\n",
    "            prefix_sums[i + 1] = prefix_sums[i] + value\n",
    "        ans = []\n",
    "        for i in range(len(queries)):\n",
    "            start, end = queries[i]\n",
    "            ans.append(prefix_sums[end + 1] - prefix_sums[start])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:\n",
    "        s = set(['a','e','i','o','u'])\n",
    "        n = len(words)\n",
    "        sumArr = [0] * n\n",
    "        ans = []\n",
    "        for i in range(n):\n",
    "            word = words[i]\n",
    "            start = word[0]\n",
    "            end = word[-1]\n",
    "            if start in s and end in s:\n",
    "                sumArr[i] = 1\n",
    "        print(sumArr)\n",
    "        for i in range(1, n):\n",
    "             sumArr[i] = sumArr[i] + sumArr[i-1]\n",
    "        print(sumArr)\n",
    "        \n",
    "        for query in queries:\n",
    "            left, right = query\n",
    "            ans.append(sumArr[right]-(0 if left ==0 else sumArr[left-1]))\n",
    "        return ans"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
